package com.lyl.lawyer.controller;

import com.cn.lyl.lawyer.model.entity.NavModel;
import com.cn.lyl.lawyer.service.NavService;
import com.cn.lyl.lawyer.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/back/nav")

public class NavController {

    @Autowired
    private NavService navService;

@PostMapping("/add")
    public Object add(NavModel navModel){
    navService.add(navModel);
    return CommonResult.success(null);
}
    @PostMapping("/delete")
    public Object delete(Integer id){
        navService.delete(id);
        return CommonResult.success(null);
    }

    @PostMapping("/edit")
    public Object edit(NavModel navModel){
        navService.change(navModel);
        return CommonResult.success(null);
    }

    @GetMapping("/findAll")
    public Object findAll(NavModel navModel){
        List<NavModel> all = navService.findAll(navModel);
        Map map = new HashMap();
        map.put("count",navService.getCount(navModel));
        map.put("list",all);
        return CommonResult.success(map);
    }

    @GetMapping("/findInfo")
    public Object findById(Integer id){
        NavModel byId = navService.findById(id);
        return CommonResult.success(byId);
    }
}
